<template>
  <div>
    <el-form class="query-table-form" @submit.native.prevent :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="项目名称查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item class="float-right">
        <el-button icon="el-icon-plus" @click="handleEdit()">资金池</el-button>
      </el-form-item>
    </el-form>
    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData"></c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <capital-edit
      :visible.sync="editVisible"
      :table-id="editId"
      :form-data="formData"
      @success="getData()"
    ></capital-edit>

    <el-dialog :visible.sync="viewVisible" top="30px" width="900px">
      <capital-view :table-id="viewId"></capital-view>
    </el-dialog>

    <list-dialog :visible.sync="listVisible" :table-id="registerId"></list-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import CapitalEdit from '@/credit/views/county/settle/capital/component/register/CapitalEdit'
import ListDialog from '@/credit/views/county/settle/capital/component/refund/ListDialog'
import CapitalView from '@/credit/views/county/settle/capital/component/refund/ApprovalInfo'

export default {
  components: {
    CapitalEdit,
    ListDialog,
    CapitalView,
  },
  props: {},
  data() {
    return {
      tableName: 'capital_pool_register',
      params: {
        index: 1,
        size: 10,
      },
      tableData: [],
      totalCount: 0,
      order: {},
      tableColumns: [
        { attrs: { label: '机构名称', prop: 'agency_name', align: 'center' } },
        { attrs: { label: '资金池金额(万元)', prop: 'capital_funds', align: 'center' } },
        { attrs: { label: '放大倍数', prop: 'multiple', align: 'center', width: '110px' } },
        { attrs: { label: '合作金额(万元)', prop: 'coo_funds', align: 'center', width: '100px' } },
        {
          attrs: { label: '合作开始时间', prop: 'coo_start_date', align: 'center', width: '100px' },
          process: v => this.$utils.dateFormat(v, 'yyyy-MM-dd'),
        },
        {
          attrs: { label: '合作结束时间', prop: 'coo_end_date', align: 'center', width: '100px' },
          process: v => this.$utils.dateFormat(v, 'yyyy-MM-dd'),
        },
        {
          attrs: { label: '缴纳时间', prop: 'pay_time', align: 'center', width: '100px' },
          process: v => this.$utils.dateFormat(v, 'yyyy-MM-dd'),
        },
        { attrs: { label: '当前余额', prop: '', align: 'center', width: '100px' } },
        { attrs: { label: '退费金额', prop: 'back_funds', align: 'center', width: '100px' } },

        {
          attrs: { label: '登记时间', prop: 'create_time', width: '100px' },
          process: v => this.$utils.dateFormat(v, 'yyyy-MM-dd hh:mm'),
        },

        {
          attrs: { label: '操作', align: 'center', width: 120 },
          operations: [
            {
              content: '修改',
              icon: 'fa fa-edit',
              event: this.handleEdit,
            },
            {
              content: '退费',
              icon: 'fa fa-cny',
              event: this.handleReFunds,
            },
            {
              content: '查看',
              icon: 'fa fa-search',
              event: this.handleView,
            },
          ],
        },
      ],
      loading: false,
      editVisible: false,
      formData: {},
      editId: '',
      viewVisible: false,
      viewId: '',
      listVisible: false,
      registerId: '',
    }
  },
  computed: {
    ...mapGetters(['clientId']),
  },
  watch: {},
  created() {
    this.params['service_id.eq'] = this.clientId
    this.getData()
  },
  mounted() {},
  methods: {
    handleReFunds(row = {}) {
      this.listVisible = true
      this.registerId = row?.id ?? ''
    },
    handleView(row = {}) {
      this.viewId = row?.id ?? ''
      this.viewVisible = true
    },
    handleEdit(row = {}) {
      this.formData = { ...row }
      this.editId = row?.id ?? ''
      this.editVisible = true
    },
    getData() {
      this.loading = true
      this.$api
        .getData(this.$serviceName, this.tableName, this.params, this.order)
        .then(res => {
          const data = res?.data ?? {}
          this.tableData = data?.data ?? []
          this.totalCount = data?.totalCount ?? 0
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>

<style lang="scss" scoped></style>
